const commissionModule = {
    namespaced: true,
    state: {
        shopInfo: {},
        //店铺全部计划数据
        shopPlanList: [],
        //产品计划
        productPlanList: []
    },
    mutations: {
        setShopInfo(state, palyload) {
            state.shopInfo = palyload
        },
        setShopPlanList(state, palyload) {
            state.shopPlanList = palyload
        },
        setProductPlanList(state, palyload) {
            if (palyload instanceof Array) {
                state.productPlanList = palyload
            }
            else {
                state.productPlanList = [palyload]
            }
        }
    },
    actions: {
        //查询产品计划
        checkProductPlanList({ state, rootState, commit }) {
            chrome.runtime.sendMessage({
                type: "custom_header",
                url: "/api/plan/queryPlanInfo",
                baseURL: "https://union.jd.com",
                params: {
                    planId: rootState.productInfo.unionGoods[0][0].planId
                }
            }, function (result) {
                commit("setProductPlanList", result.data)
            });
        },
        //查询店铺信息
        checkShopInfo({ state, rootState, commit }) {
            chrome.runtime.sendMessage({
                type: "custom_header",
                url: "/api/shop/queryShopInfo",
                baseURL: "https://union.jd.com",
                params: {
                    shopId: rootState.JTTProductInfo.shopInfo.shopId
                }
            }, function (result) {
                    commit("setShopInfo", result.data) 
            });
        },
        //查询店铺计划
        checkShopPlanList({ state, rootState, commit }) {
            chrome.runtime.sendMessage({
                type: "custom_header",
                url: "/api/shop/queryShopPlanList",
                baseURL: "https://union.jd.com",
                params: {
                    shopId:  rootState.JTTProductInfo.shopInfo.shopId
                }
            }, function (result) {
                    commit("setShopPlanList", result.data)
            });
        }
    }
}
export default commissionModule